/*
 * @Author: Clark
 * @Email: haixuanwoTxh@gmail.com
 * @Date: 2022-03-31 10:52:53
 * @LastEditors: Clark
 * @LastEditTime: 2022-10-14 14:31:11
 * @Description: file content
 */

#ifndef DEBUG_LOG_H
#define DEBUG_LOG_H

#include <stdio.h>

// #define DEBUG_LOG_ENABLE        // 日志模块总开关，注释掉将关闭日志输出

#ifdef DEBUG_LOG_ENABLE
    #define DEBUG(format, ...) printf(format, ##__VA_ARGS__)
#else
    #define DEBUG(format, ...)
#endif

// 日志级别
enum LOG_LEVEL {
    LOG_LEVEL_FATAL,
    LOG_LEVEL_ERR,
    LOG_LEVEL_WARN,
    LOG_LEVEL_INFO,
    LOG_LEVEL_DEBUG,
};

// 设置日志级别
#define DEBUG_LEVEL LOG_LEVEL_DEBUG
// #define DEBUG_LEVEL LOG_LEVEL_INFO
// #define DEBUG_LEVEL LOG_LEVEL_WARN
// #define DEBUG_LEVEL LOG_LEVEL_ERR
// #define DEBUG_LEVEL LOG_LEVEL_FATAL

#define log_fatal(format, ...) \
    do { \
         if(DEBUG_LEVEL >= LOG_LEVEL_FATAL)\
           DEBUG("FATAL-> FUNC:%s FILE:%s LINE:%d " format "\n", \
                     __func__, __FILE__, __LINE__, ##__VA_ARGS__);\
    } while (0)

#define log_err(format, ...) \
    do { \
         if(DEBUG_LEVEL >= LOG_LEVEL_ERR)\
           DEBUG("ERR-> FUNC:%s FILE:%s LINE:%d " format "\n", \
                     __func__, __FILE__, __LINE__, ##__VA_ARGS__ );\
    } while (0)

#define log_warn(format, ...) \
    do { \
         if(DEBUG_LEVEL >= LOG_LEVEL_WARN)\
           DEBUG("WARN-> FUNC:%s " format "\n", __func__, ##__VA_ARGS__);\
    } while (0)

#define log_info(format, ...) \
    do { \
         if(DEBUG_LEVEL >= LOG_LEVEL_INFO)\
           DEBUG("INFO->" format "\n", ##__VA_ARGS__);\
    } while (0)

#define log_debug(format, ...) \
    do { \
         if(DEBUG_LEVEL >= LOG_LEVEL_DEBUG)\
            DEBUG(format "\n", ##__VA_ARGS__);\
    } while (0)

#endif
